//编辑弹层
function gendan(obj) {
	$(obj).removeAttr("onclick");
    var islogin = "<?php echo Session('eai')['tel']?>";
    if(!islogin){
        //用户未登录
        msg('请先登录');
        setTimeout(function(){
        	window.location.href = gotologin;
        },2000)
        return false;
    }
    var infofinish = '{{$infofinish}}';
    if(infofinish == 1){
        var gowanshan = "{{url('/authenticate?id=info')}}";
        $('.popUp').hide();
        msg('请完善资料');
        window.setTimeout(window.location.reload(),2000);
        return false;
    }else{
  		$('.follow_btn').show();
  		$('.l_mask').show();
        aid              = $(obj).attr('analyst_id');
        analyst_username = $(obj).attr('analyst_username');
        status           = $(obj).attr('status');
        direction        = $(obj).attr('direction');
        var button_html = $('.l_master_title button').html();
        if(button_html == "订阅") {
            var cancleBtn=$(".foot_right>input");
            cancleBtn.css({"visibility":"hidden"});
        }
        if(button_html == "编辑") {
            var thisBtn=this;
        }
//      if(status == 1){
//          $('#gendancancle').show();
//          $('.follow_btn').attr('id','follow_btn_cancel');
//      }else{
//          $('#gendancancle').hide();
//      }
    }
}
var myAttr;
//移除确定和取消按钮点击事件
function cancle(){
	$('.follow_btn').hide();
	window.setTimeout(window.location.reload(),2000);
}
function sure(obj){
	var eleAttr1 = $('.follow_btn .bor span').eq(0).attr('class');
	var eleAttr2 = $('.follow_btn .bor span').eq(1).attr('class');
	var isChecked = $(".squar input[type='checkbox']").is(':checked');
	if(direction == '0') { //正向订阅
		direction == 0;
	}else if(direction == '1'){ //反向订阅
		direction == 1;
	}
	if(eleAttr1 == 'current' && isChecked || eleAttr2 == 'current' && isChecked) {
		$.ajax({
	        url:  gotofllow,
	        type: 'post',
	        data: {'analystid':aid,'analystname':analyst_username,'status':status,'direction':direction},
	        headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') },
	        dataType:'json',
	        success: function(res){
	            if(res.status == 0){
	                //订阅失败
	               msg('订阅失败');
	                window.setTimeout(window.location.reload(),2000);
	            }else if(res.status == 2){
	                //用户未登录
	                msg('请先登录');
	                setTimeout(function(){
	                	window.location.href = gotologin;
	                },2000)
	            }else if(res.status == 3){
	                //用户未登录
	                msg('订阅已达上限');
	                window.setTimeout(window.location.reload(),2000);
	            }else{
	                //订阅成功
	                msg('订阅成功');
	                window.setTimeout(window.location.reload(),2000);
	            }
	        }
	    });
		$('.follow_btn').hide();
	}else if(eleAttr1 == '' && eleAttr2 == '' && !isChecked) {
		msg('选择方向和协议');
        return false;
	}else if(eleAttr1 == 'current'  && !isChecked || eleAttr2 == 'current' && !isChecked) {
		msg('选择协议');
        return false;
	}else {
		msg('选择方向');
        return false;
	}
}
//取消订阅
function follow(status,direction,obj){
    var isChecked = $(".squar input[type='checkbox']").is(':checked');
	if(!isChecked) {
		msg('请勾选协议');
		$('.follow_btn').show();
	}else{
        $(obj).removeAttr('onclick');
        $.ajax({
            url:gotofllow,
            type: 'post',
            data: {'analystid':aid,'analystname':analyst_username,'status':status,'direction':direction},
            headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') },
            dataType:'json',
            success: function(res){
                if(res.status == 0){
                    //订阅失败
                   msg('订阅失败');
                    window.location.reload();
                }else if(res.status == 2){
                    //用户未登录
                    msg('请先登录');
                    setTimeout(function(){
                    	window.location.href = gotologin;
                    },2000)
                }else if(res.status == 3){
                    //用户未登录
                    msg('订阅已达上限');
                    window.setTimeout(window.location.reload(),2000);
                }else{
                    //订阅成功
                    msg('操作成功');
                    window.setTimeout(window.location.reload(),2000);
                }
            }
        });
    }
}
